<!-- // created by: alfin akhret 
 // created by: alfin akhret
// related files :
// model/mdue_date.php
// view/f-due-date.php
// view/grid-due-date.php
// library/serversidedatatables.php 
-->
<!-- delete confirmation dialog box -->
<div id="delConfDialog" title="Confirm">
    <p>Anda yakin?</p>
</div>
<!-- message dialog box -->
<div id="msgDialog"><p></p></div>

<!-- edited by : alfin akhret
SSP datattables -->
<table id="records" class="handsetRecord">
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>
<!--  -------------->

<script type="text/javascript">
var readUrl   = 'index.php/consignment_list/get_consignment_list';
updateUrl = '<?=base_url();?>index.php/consignment_takeout/index'
pdfurl='index.php/consignment_takeout/pdf'
// delUrl    = '<?=base_url();?>index.php/group_alias/delete';
  

$( function() {
    readUsers();
    $( '#msgDialog' ).dialog({
        autoOpen: false,
        buttons: {
            'Ok': function() {
                $( this ).dialog( 'close' );
            }
        }
    });
    
    $( '#delConfDialog' ).dialog({
        autoOpen: false,
        buttons: {
            'No': function() {
                $( this ).dialog( 'close' );
            },
            'Yes': function() {
                //display ajax loader animation here...
                $( '#ajaxLoadAni' ).fadeIn( 'slow' );
                $( this ).dialog( 'close' );
                $.ajax({
                    url: delHref,
                    success: function( response ) {
                        //hide ajax loader animation here...
                        $( '#ajaxLoadAni' ).fadeOut( 'slow' );
                        
                        $( '#msgDialog > p' ).html( response );
                        $( '#msgDialog' ).dialog( 'option', 'title', 'Success' ).dialog( 'open' );
                        
                        $( 'a[href=' + delHref + ']' ).parents( 'tr' )
                        .fadeOut( 'slow', function() {
                            $( this ).remove();
                        });
                        
                    } //end success
                });
            } //end Yes
        } //end buttons
    }); //end dialog
    
    
    $( '#records' ).delegate( 'a.deleteBtn', 'click', function() {
        delHref = $( this ).attr( 'href' );
        $( '#delConfDialog' ).dialog( 'open' );
            return false;
    }); //end delete delegate
    // --- Create Record with Validation ---
}); //end document ready

function readUsers() {
    $('.handsetRecord').dataTable({
                "bJQueryUI": true, // aktifkan tampilan tabel JQueryUI
                "sAjaxSource": readUrl, //data source
                "sAjaxDataProp": "aaData", //variabel yg menampung data table
                "bServerSide": true, //serverside processing true
                "bProcessing": true, // tampilkan 'processing...' status saat data dipanggil
                // "sPaginationType": 'full_numbers',
                "bPaginate": true,
                "aoColumns":[ //tentukan kolom pd tabel yg akan menampung value dari server
                    {"mDataProp": "no_consignment", "sTitle": "Nomor Konsinyasi"}, 
                    {"mDataProp": "sales", "sTitle": "Sales"}, 
                    {"mDataProp": "tgl_consignment", "sTitle": "Tanggal Konsinyasi"}, 
                    {"mDataProp": "partner", "sTitle": "Partner"}
                ],
                "fnRowCallback": function(nRow, aaData, iDisplayIndex, iDisplayIndexFull) 
                {
                    $(nRow).find('td').eq(0).before('<td>'+(parseInt(iDisplayIndex,10)+1+parseInt(dis))+'</td>'); //20120719 ayu
                    $(nRow).find('td').eq(-1).after('<td><a href="'+updateUrl+'/'+aaData[0]+'">View</a> | <a href="'+pdfurl+'/'+aaData[0]+'">PDF</a></td>');

                    // $(nRow).find('td').eq(0).before('<td>'+ no++ +'</td>');
                    // $(nRow).find('td').eq(0).replaceWith(function() {
                    //     var url = $.trim($(this).text());
                    //     return '<a href="<?=base_url();?>index.php/sell/getDetail/' + url.replace(/^0+/, '') + '">' + url + '</a>';
                    // });
                        $.ajax({
                               url: "<?=base_url();?>index.php/consignment_list/defoger",
                               type: "POST",
                               data: {'str' : aaData[0]},
                               success: function(response) {
                                   /*$(nRow).find('td').eq(0).replaceWith(response);*/
                                   $(nRow).find('td').eq(1).replaceWith(response); //20120719 ayu
                               }
                        });
    
                    return nRow;
                }, //20120719 ayu
                
                "fnServerData": function ( sSource, aoData, fnCallback ) { 
                    $.getJSON( sSource, aoData, function (json) { 
                                
                    dis=json['iDisplayStart'];
                    fnCallback(json);
                });}
        });
        no=1;
        $('.handsetRecord thead tr').find('th').eq(0).before('<th class="ui-state-default">No</th>'); //20120719 ayu
        $('.handsetRecord thead tr').find('th').eq(-1).after('<th class="ui-state-default" width="200px">Action</th>');
        // $('.handsetRecord thead tr').find('th').eq(0).before('<th class="ui-state-default" width="50px">No</th>');
}

function client_defog(the_fog)
{
    // $.ajax({
    //        url: "<?=base_url();?>index.php/consignment_list/defoger/"+the_fog,
    //        type: "POST",
    //        success: function(data) {
    //            return data;
    //        }
    //    });
}
</script>
